package com.qx.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qx.entity.Roles;
import com.qx.service.RolesService;

@RestController
@CrossOrigin(origins="*")
public class RolesController {
	
	@Autowired
	RolesService rolesService;
	@RequestMapping("/findRoles")
	public Object findRoles(Integer page,Integer limit) {
		int count=rolesService.count();
		Map<String, Object> map=new HashMap<String, Object>();
		map.put("code", 0);
		map.put("msg", "");
		map.put("data", rolesService.findRoles(page, limit).getContent());
		map.put("count", count);
		return map;
	}
	@RequestMapping("/addRoles")
	public Object addRoles(Roles roles) {
		try {
			rolesService.save(roles);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}
	@RequestMapping("/updateRoles")
	public Object updateRoles(Roles roles) {
		try {
			rolesService.save(roles);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}
	
	@RequestMapping("/deleteRoles")
	public Integer deleteRoles(Integer id) {
		try {
			rolesService.deleteRoles(id);
			return 1;
		} catch (Exception e) {
			return 0;
		}
	}
	

}
